// Copyright (C) Microsoft Corporation. All rights reserved.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;


namespace Microsoft.DDSolutions.UI
{
    /// <summary>
    ///  Title Bar using a Panel
    /// </summary>
    public class TitlePanel : Panel
    {
        private bool m_isTitle = true;
        private Label lblMessage = new Label();
        public TitlePanel()
        {
            InitializeComponent();
        }


        [Description("Is it a Title Bar"), Category("Appearance")]
        public bool IsTitle
        {
            get
            {
                return m_isTitle;
            }

            set
            {
                m_isTitle = value;
            }
        }
        /// <summary>
        ///  Caption to display for the Title
        /// </summary>
        public string Caption
        {
            get
            {
                return lblMessage.Text;
            }

            set
            {
                lblMessage.Text = value;
            }
        }

        /// <summary>
        ///  Caption Font
        /// </summary>
        public Font CaptionFont
        {
            get
            {
                return lblMessage.Font;
            }

            set
            {
                lblMessage.Font = value;
            }
        }


        private void InitializeComponent()
        {
            this.lblMessage = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // lblMessage
            // 
            this.lblMessage.AutoSize = true;
            this.lblMessage.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lblMessage.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
            this.lblMessage.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.lblMessage.Location = new System.Drawing.Point(12, 5);
            this.lblMessage.Name = "lblMessage";
            this.lblMessage.Size = new System.Drawing.Size(0, 13);
            this.lblMessage.TabIndex = 0;
            this.lblMessage.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // TitlePanel
            // 
            this.BackColor = System.Drawing.SystemColors.Control;
            this.Controls.Add(this.lblMessage);
            this.Dock = System.Windows.Forms.DockStyle.Top;
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
            e.Graphics.SmoothingMode = SmoothingMode.HighQuality;

            base.OnPaint(e);

            this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(51)))), ((int)(((byte)(153)))));

            Rectangle hline;
            LinearGradientBrush hlinebr;



            if (IsTitle)
            {
                hline = new Rectangle(0, this.Height - 3, this.Width, 3);
                hlinebr = new LinearGradientBrush(hline, Color.FromArgb(0, 51, 153), Color.FromArgb(140, 170, 230), LinearGradientMode.Horizontal);
            }
            else
            {
                hline = new Rectangle(0, 0, this.Width, 3);
                hlinebr = new LinearGradientBrush(hline, Color.FromArgb(62, 53, 171), Color.FromArgb(255, 153, 51), LinearGradientMode.Horizontal);
            }

            e.Graphics.FillRectangle(hlinebr, hline);
        }
    }
}
